<?php

namespace common\models;

use Yii;
use yii\behaviors\TimestampBehavior;
use yii\db\ActiveRecord;
/**
 * This is the model class for table "xa_link".
 *
 * @property integer $id
 * @property string $xa_parent_id
 * @property string $xa_name
 * @property string $xa_title
 * @property string $xa_url
 * @property string $xa_picture
 * @property string $xa_create_time
 * @property string $xa_update_time
 * @property string $xa_remark
 */
class Link extends \yii\db\ActiveRecord
{
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'xa_link';
    }


    public function behaviors() {
        return [
            [
                'class'=>TimestampBehavior::className(),
                'attributes'=>[
                    //创建时间
                    ActiveRecord::EVENT_BEFORE_INSERT=>['xa_create_time','xa_update_time'],
                    //修改时间
                    ActiveRecord::EVENT_BEFORE_UPDATE=>['xa_update_time']

                ],
                //设置默认值
                'value'=>date('Y-m-d H:i:s')

            ]

        ];
    }
    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['xa_title'], 'required'],
            [['xa_parent_id'], 'string', 'max' => 50],
            [['xa_name', 'xa_title', 'xa_url', 'xa_picture', 'xa_remark'], 'string', 'max' => 255],
            [['xa_create_time', 'xa_update_time'], 'string', 'max' => 100],
        ];
    }



    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'xa_parent_id' => '上级链接',
            'xa_name' => '链接名称',
            'xa_title' => '链接标题',
            'xa_url' => '链接地址',
            'xa_picture' => '链接图片',
            'xa_create_time' => '创建时间',
            'xa_update_time' => '更新时间',
            'xa_remark' => '备注',
        ];
    }
}
